import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

/**
 * @author LKQ
 * @date 2021/12/20 16:27
 * @description 只出现一次的数字
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 1, 2, 3, 4, 5, 5, 4};
        System.out.println(Arrays.toString(solution.singleNumber(nums)));
    }

    public int[] singleNumber(int[] nums) {
        Stack<Integer> stack = new Stack<>();
        Arrays.sort(nums);
        for (int num : nums) {
            if (stack.isEmpty()) {
                stack.add(num);
            } else {
                if (stack.peek() != num) {
                    stack.add(num);
                } else {
                    stack.pop();
                }
            }
        }
        int[] ans = new int[2];
        int start = 0;
        for (Integer a: stack) {
            ans[start++] = a;
        }
        return ans;
    }
}
